import React from 'react'
import { Redirect, Route } from 'react-router-dom'//BrowserRouter模式，路径

export default function Auth(props: { path: string; children: React.ReactNode }) {
    return <Route path={props.path} render={() => {
        // 判断是否有权限,如果有权限就渲染这个路由组件否则就重定向回登录组件
        return localStorage.getItem('token') ? props.children : <Redirect from={props.path} to='/login' exact />;
    }}></Route>

}
